/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rw.magallanes.ide.action;

import com.rw.magallanes.core.Item;
import com.rw.magallanes.core.Warehouse;
import com.rw.magallanes.ide.main.MainFrame;
import com.rw.magallanes.ide.main.MainSystem;
import com.rw.magallanes.utilities.MessageType;
import com.rw.magallanes.utilities.Utilities;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;

/**
 *
 * @author Gonzalez
 */
public class DeleteItemAction extends AbstractAction {

    @Override
    public void actionPerformed(ActionEvent e) {
        MainSystem ms = MainSystem.getInstance();
        MainFrame mf = ms.getMainFrame();

        Item item = mf.getSelectedItem();
        if (item != null) {
            Warehouse wh = mf.getWarehouse();
            wh.deleteItem(item);
            mf.updateItemsFor(item.getCategory());
        } else {
            Utilities.showMsg(mf, "Seleccione un item", MessageType.WARN);
        }

    }

    @Override
    public Object getValue(String key) {
        if (key.compareTo(NAME) == 0) {
            return "Eliminar Item";
        } else {
            return super.getValue(key);
        }
    }
}
